package com.david.nfc.result

import android.content.Context
import android.content.Intent

class MusicParser: NfcParser {
    override fun parseResult(context: Context, resultBean: NfcResultBean): Boolean {
        if (TYPE_MUSIC == resultBean.type) {
            when(resultBean.action){
                ACTION_PLAYPAUSE -> {

                    val intent = Intent(Intent.ACTION_VIEW)
                    val packageName = "com.david.musicapp" //另一个app的包名
                    val className = "com.david.musicapp.PlayService" //另一个app要启动的组件的全路径名
                    intent.setClassName(packageName, className)
                    intent.putExtra("SONG_ACTION_TYPE_KEY", 9)
//                    activity.startService(intent);//或者bindService(intent, mConnection, Context.BIND_AUTO_CREATE); 都能启动

                    context.startForegroundService(intent)
                }
            }
            return true
        }
        return false
    }
}